package com.example.demo.service.zl;
import com.example.demo.dao.zl.PermissionDao1;
import com.example.demo.entity.Permission;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class PermissionServiceImpl implements PermissionService {
    @Autowired(required = true)
    PermissionDao1 permissionDao1;
    @Override
    public List<Permission> FINDALL() {
        List<Permission> userList= permissionDao1.FINDALL();
        return  userList;
    }

    @Override
    public List<Permission> findByName(String name) {
        List<Permission> userList= permissionDao1.findByName(name);
        return userList;
    }

    @Override
    public List<Permission> insert( String name,String descripion,String url,String  pid,String perms,int type, String icon,int order_num) {
        String permissionnametemp=name;
        int single = permissionDao1.insert(permissionnametemp,descripion,url,pid,perms,type,icon,order_num);
        if(single>=1){
            List<Permission> userListAfterInsert= permissionDao1.findByName(permissionnametemp);
            return userListAfterInsert;
        } else {
            System.out.println("error insert");
            return null;
        }
    }

    @Override
    public int delete(int id) {
        int deleteSingle = permissionDao1.delete(id);
        if(deleteSingle>=1){
            System.out.println("删除一行");
            return 1;
        } else {
            System.out.println("无数据");
            return 0;
        }
    }

    @Override
    public List<Permission> update(int id,String name,String descripion,String url,String  pid,String perms,int type, String icon,int order_num) {
        String permissionnametmp = name;
        int update = permissionDao1.update(id,permissionnametmp,descripion,url,pid,perms,type,icon,order_num);
        if (update>=1){
            List<Permission> userList= permissionDao1.findByName(permissionnametmp);
            return userList;
        } else {
            return null;
        }
    }


}